package com.xhwy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                //是否发送Cookie
//                .allowCredentials(true)
//                //放行哪些原始域
//                .allowedOrigins("*")
//                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE"})
//                .allowedHeaders("*").exposedHeaders("*");
        //设值可以跨域请求的方法allowedMethods()
        //restfull风格里的方法："GET","POST","PUT","DELETE" (注意：大写)
        registry.addMapping("/**")
                .allowedMethods("GET","POST","PUT","DELETE")
                .allowCredentials(true);//允许前台携带凭据
    }

//    //配置静态资源访问
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //访问路径
//        registry.addResourceHandler("/static/**")
//                //映射的真实路径
//                .addResourceLocations("classpath:/static/");
//    }
}
